package cn.gailvlun.gll.presentation.emotion.util

import android.graphics.drawable.Drawable
import android.text.Html
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.SpannedString
import android.text.style.ForegroundColorSpan
import android.view.View
import cn.gailvlun.gll.R
import cn.gailvlun.gll.chatlib.bean.SystemNotification
import cn.gailvlun.gll.net.emotion.Comment
import cn.gailvlun.gll.net.emotion.Emotion
import cn.gailvlun.gll.net.emotion.EmotionEnum
import cn.gailvlun.gll.presentation.base.App



object Util {
    @JvmStatic
    fun getTime(emotion: Emotion): String {
        return EmotionDateUtil.commentTimeFormat(emotion.created)
    }

    @JvmStatic
    fun getHeartTime(snf: SystemNotification): String {
        return EmotionDateUtil.commentTimeFormat(snf.created)
    }

    @JvmStatic
    fun getLocaleEnglishTimeFormat(emotion: Emotion): String {
        return EmotionDateUtil.localeEnglishTimeFormat(emotion.created)

    }

    @JvmStatic
    fun getDayTimeFormat(emotion: Emotion): String {
        val localDateTime = EmotionDateUtil.dateTimeFormat(emotion.created)
        return localDateTime.toString("dd")

    }

    @JvmStatic
    fun getEmotionCreatedTime(e: Emotion): String {
        val localDateTime = EmotionDateUtil.dateTimeFormat(e.created)
        return localDateTime.toString("HH:mm")
    }

    @JvmStatic
    fun getMyEmotionCount(vararg text: Int): Spanned {
        val count = App.getInstance().resources.getString(R.string.emotion_square_my_emotion_count, text[0], text[1])
        return Html.fromHtml(count)
    }


    

    @Deprecated(
            message = "有情绪类型有变动，原先的先不做删除，万一tmd又变回来",
            replaceWith = ReplaceWith(expression = "Util.get10KindsEmotionSmallIcon(emotionState)", imports = "Util")
    )
    @JvmStatic
    fun getSmallEmotionState(emotion: Emotion): Drawable {
        return when (emotion.emotion) {
            EmotionEnum.S -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_satisfy_small)
            EmotionEnum.T -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_laugh_cry_small)
            EmotionEnum.F -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_sad_small)
            EmotionEnum.A -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_angry_small)
            EmotionEnum.N, EmotionEnum.X -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_satisfy_small)
            else -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_satisfy_small)
        }
    }

    @Deprecated(
            message = "有情绪类型有变动，原先的先不做删除，万一tmd又变回来",
            replaceWith = ReplaceWith(expression = "Util.get10KindsEmotionMiddleIcon(emotionState)", imports = "Util")
    )
    @JvmStatic
    fun getMiddleEmotionState(emotion: Emotion): Drawable {
        return when (emotion.emotion) {
            EmotionEnum.S -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_satisfy_middle)
            EmotionEnum.T -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_laugh_cry_middle)
            EmotionEnum.F -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_sad_middle)
            EmotionEnum.A -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_angry_middle)
            EmotionEnum.N, EmotionEnum.X -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_satisfy_middle)
            else -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_satisfy_middle)
        }
    }


    @JvmStatic
    fun get10KindsEmotionSmallIcon(emotionEnum: EmotionEnum?): Drawable? {

        return when (emotionEnum) {
            EmotionEnum.S -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_s_small)

            EmotionEnum.A -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_a_small)
            EmotionEnum.F -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_f_small)

            EmotionEnum.X -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_x_small)
            EmotionEnum.C -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_c_small)
            EmotionEnum.L -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_l_small)

            EmotionEnum.E -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_e_small)
            else -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_o_small)
        }

    }

    @JvmStatic
    fun get10KindsEmotionMiddleIcon(emotionEnum: EmotionEnum?): Drawable? {

        return when (emotionEnum) {
            EmotionEnum.S -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_s_middle)

            EmotionEnum.A -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_a_middle)
            EmotionEnum.F -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_f_middle)

            EmotionEnum.X -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_x_middle)
            EmotionEnum.C -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_c_middle)
            EmotionEnum.L -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_l_middle)

            EmotionEnum.E -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_e_middle)
            else -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_o_middle)
        }

    }

    

    @Deprecated("popupwindow被去掉")
    @JvmStatic
    fun getLikeText(emotion: Emotion): String {

        return when (emotion.emotion) {
            EmotionEnum.S -> {
                "为ta高兴"
            }
            EmotionEnum.F, EmotionEnum.L -> {
                "抱抱"
            }
            EmotionEnum.A -> {
                "送ta握草"
            }
            else -> {
                ""
            }
        }















    }

    @JvmStatic
    fun getLikeText2(emotion: Emotion): String {

        return when (emotion.emotion) {
            EmotionEnum.S -> {
                "为你高兴"
            }
            EmotionEnum.F, EmotionEnum.L -> {
                "抱抱"
            }
            EmotionEnum.A -> {
                "送你一把握草"
            }
            else -> {
                ""
            }
        }
    }

    @JvmStatic
    fun getLikeIcon(emotion: Emotion): Drawable? {

        return when (emotion.emotion) {
            EmotionEnum.S -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_s_icon0_selected)

            }
            EmotionEnum.F, EmotionEnum.L -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_f_icon0_selected)

            }
            EmotionEnum.A -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_a_icon0_selected)

            }
            else -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_heart_right_small)
            }

        }































    }


    @Deprecated("popupwindow被去掉")
    @JvmStatic
    fun getLikeShortText(emotion: Emotion): String? {
        return ""











    }

    @JvmStatic
    fun getLikeIconSelector(emotion: Emotion): Drawable? {

        return when (emotion.emotion) {
            EmotionEnum.S -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_s_icon0)

            }
            EmotionEnum.F, EmotionEnum.L -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_f_icon0)

            }
            EmotionEnum.A -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_state_a_icon0)

            }
            else -> {
                App.getInstance().resources.getDrawable(R.drawable.icon_emotion_heart_right)
            }

        }









    }


    @JvmStatic
    fun getLikeLeftIcon(emotion: Emotion): Drawable? {
        return when (emotion.emotion) {



            else -> App.getInstance().resources.getDrawable(R.drawable.icon_emotion_heart_left)
        }





    }

    @JvmStatic
    fun getLikeLeftText(emotion: Emotion, heartCounts: Int): String? {
        return when (emotion.emotion) {
            EmotionEnum.S -> {
                "${heartCounts}人为ta高兴"
            }
            EmotionEnum.F, EmotionEnum.L -> {
                "${heartCounts}抱抱"
            }
            EmotionEnum.A -> {
                "${heartCounts}人送ta握草"
            }
            else -> {
                "${heartCounts}"
            }
        }
    }

    @JvmStatic
    fun controlReadVisible(emotion: Emotion): Int {

        return when (emotion.emotion) {
            EmotionEnum.S, EmotionEnum.F, EmotionEnum.A -> {
                View.GONE
            }
            else -> {
                View.VISIBLE
            }

        }

    }


    @JvmStatic
    fun getCommentContent(item: Comment): Spanned {
        val focusColor = App.getInstance().resources.getColor(R.color.apricot)
        return if (item.reply == null) {
            SpannedString(item.text)
        } else {




            val append = SpannableStringBuilder()
                    .append("回复")
                    .append("@${item.reply.name}")
                    .append(":")
                    .append(item.text)
            append.setSpan(
                    ForegroundColorSpan(focusColor),
                    2,
                    2 + item.reply.name.length+1,
                    Spanned.SPAN_INCLUSIVE_EXCLUSIVE

            )

            append

        }
    }
}